<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="直播课名称" prop="teachcastName" label-width="100px">
        <el-input
          v-model="queryParams.teachcastName"
          placeholder="请输入直播课名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="直播教师" prop="teacherName">
        <el-input
          v-model="queryParams.teacherName"
          placeholder="请输入直播教师"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="直播时间">
        <el-date-picker
          v-model="dateRange"
          style="width: 240px"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"

        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <el-table v-loading="loading" :data="manHourList" @selection-change="handleSelectionChange" @row-dblclick="handleRowDoubleClick">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column header-align="left" align="left" prop="channelid" label="频道号" />
      <el-table-column prop="teachcastName" header-align="left" align="left" label="直播课名称" />
      <el-table-column prop="teachcastContent" header-align="left" align="left" label="直播内容" />
      <el-table-column header-align="left" align="left" prop="teacherName" label="直播教师" />
      <el-table-column header-align="left" align="left" prop="teachcastTime" label="直播时间" />
      <el-table-column header-align="left" align="left" prop="teachcastDepcName" label="直播对象" />
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改日精进打卡对话框 -->
    <el-drawer
      :withHeader="true"
      :title="title"
      :visible.sync="open"
      :with-header="false"
      size="30%"
    >
<!--      <div style="padding: 0 30px; height: 93%">-->
<!--        <el-form ref="form" :model="form" label-width="80px">-->
<!--          <el-form-item label="项目名称" prop="projectName">-->
<!--            <el-input v-model="form.projectName" type="textarea" :disabled="true" placeholder="请输入内容"-->
<!--                      :autosize="{ minRows: 4, maxRows: 20}"/>-->
<!--          </el-form-item>-->
<!--          <el-form-item label="任务名称" prop="quest">-->
<!--            <el-input v-model="form.quest" type="textarea" :disabled="true" placeholder="请输入内容"-->
<!--                      :autosize="{ minRows: 4, maxRows: 6}"/>-->
<!--          </el-form-item>-->
<!--          <el-form-item label="报工内容" prop="reportingContent">-->
<!--            <el-input v-model="form.reportingContent" type="textarea" :disabled="true" placeholder="请输入内容"-->
<!--                      :autosize="{ minRows: 4, maxRows: 6}"/>-->
<!--          </el-form-item>-->
<!--          <el-row>-->
<!--            <el-col :span="6">-->
<!--              <el-form-item label="所用工时" prop="manHour">-->
<!--                <el-input v-model="form.manHour" :disabled="true" placeholder="请输入工时"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :span="8">-->
<!--              <el-form-item label="填写人" prop="createUser">-->
<!--                <el-input v-model="form.createByName" :disabled="true" placeholder="请输入填写人"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--            <el-col :span="10">-->
<!--              <el-form-item label="填写时间" prop="createTime">-->
<!--                <el-input v-model="form.createTime" :disabled="true" placeholder="请输入填写时间"/>-->
<!--              </el-form-item>-->
<!--            </el-col>-->
<!--          </el-row>-->
<!--        </el-form>-->
<!--      </div>-->
    </el-drawer>
  </div>
</template>

<script>
import {getManHour, queryHourByTime} from "@/api/system/mis/manHour";
import {delManHourDetail, getManHourDetail, listManHourDetail} from "@/api/system/mis/manHourDetail";
import moment from "moment";
import {getMethod} from "@/api/system/livelesson/quote";

export default {
  name: "ManHour",
  data() {
    return {
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工时填报表格数据
      manHourList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      queryTime: undefined,
      hourLoading:false,
      hourData:[],
      dateOne: [],
      dateRange: [],
      content: '今日未填写人数：',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        teacherCode: '',
        teacherName: '',
        teachcastName: '',
      },
      form:{}
    };
  },
  created() {
    this.queryTime = new Date();
    this.queryTime = moment().format('YYYY-MM-DD HH:mm:ss');
    this.getList();

  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      this.queryParams.teacherCode = this.$store.state.user.name
      // this.queryByTime()
      getMethod("/livelesson/teachcast/list",this.addDateRange(this.queryParams,this.dateRange)).then(response => {
        this.manHourList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange =[]
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.dateOne = selection
      this.ids = selection.map(item => item.id)
      this.idSons = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$router.push({
        path: "/livelesson/teachcastForm",
        query: {
          isView: 'add'
        },
      });
    },
    // 双击列表
    handleRowDoubleClick(row) {
      debugger
      const id = row.id || this.ids
      getManHourDetail(id).then(response => {
        this.open = true;
        this.loading = false;
        this.form = response.data;
        this.title = "查看工时详情";
      });
    },
    queryTimeChange(row){
      if (row !== null){
        // this.queryByTime()
      }
    },
    /** 查询未填写人数 */
    handleLinkClick(row){
      this.$router.push({
        path: "/everyWork/manHourForm",
        query: { isView: 'view',id: row.refId},
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      if (this.dateOne[0].teacherCode !== this.$store.state.user.name){
        return this.$message.warning("只能修改自己创建的直播课")
      }
      if (this.ids.length > 1){
        return this.$message.warning("请选择一条记录")
      }
      const id = this.ids[0]
      this.$router.push({
        path: "/livelesson/teachcastForm",
        query: {
          id: id,
          isView: 'edit'
        },
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.idSons;
      console.log(ids)
      this.$modal.confirm('是否确认删除数据？').then(() => {
        this.loading = true;
        return delMethod("/livelesson/teachcast/" + ids);
      }).then(() => {
        this.loading = false;
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      }).finally(() => {
        this.loading = false;
      });
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download('system/manHour/export', {
        ...this.queryParams
      }, `工时填报.xlsx`)
    }
  }
};
</script>
<style lang="scss" scoped>
.ellipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
